package dgut.bbm.service.impl;


import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import dgut.bbm.common.utils.PageUtils;
import dgut.bbm.common.utils.Query;

import dgut.bbm.dao.FindOwnerDao;
import dgut.bbm.entity.FindOwnerEntity;
import dgut.bbm.service.FindOwnerService;
import org.springframework.util.StringUtils;


@Service("findOwnerService")
public class FindOwnerServiceImpl extends ServiceImpl<FindOwnerDao, FindOwnerEntity> implements FindOwnerService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<FindOwnerEntity> page = this.page(
                new Query<FindOwnerEntity>().getPage(params),
                new QueryWrapper<FindOwnerEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils queryPageByCondition(Map<String, Object> params) {
        QueryWrapper<FindOwnerEntity> queryWrapper = new QueryWrapper<>();
        String title = (String) params.get("title");
        if(!StringUtils.isEmpty(title)){
            queryWrapper.and((wrapper)->{
                wrapper.eq("title",title).or().like("title",title);
            });
        }

        String content = (String) params.get("content");
        if(!StringUtils.isEmpty(content)){
            queryWrapper.and((wrapper)->{
                wrapper.eq("content",content).or().like("content",content);
            });
        }

        IPage<FindOwnerEntity> page = this.page(new Query<FindOwnerEntity>().getPage(params), queryWrapper);

        return new PageUtils(page);
    }


}